package com.zeng.sim.util;

/**
 * 描述信息
 *
 * @author zengwanlin
 * @date 2023-12-20T14:34
 */
public class SimConstant {

    /**
     * 有效标识 0-无效
     */
    public static final String VALID_FLAG_0 = "0";

    /**
     * 有效标识 1-有效
     */
    public static final String VALID_FLAG_1 = "1";

    /**
     * 业务类型 01-客户端
     */
    public static final String BUSI_TYPE_01 = "01";

    /**
     * 业务类型 02-服务端
     */
    public static final String BUSI_TYPE_02 = "02";

    /**
     * 报文渠道号 NONE
     */
    public static final String MSG_CHANNEL_NO_NONE = "NONE";

    /**
     * 系统配置类型-系统配置
     */
    public static final String SYS_CONFIG_TYPE_SYSTEM = "system";

    /**
     * 报文通信协议
     */
    public enum MsgProtocol {

        MSG_PROTOCOL_SOCKET("SOCKET", "SOCKET通信"),

        MSG_PROTOCOL_HTTP("HTTP", "HTTP通信");

        private String code;

        private String name;

        MsgProtocol(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public String getName() {
            return name;
        }

        public static MsgProtocol getInstance(String code) {
            MsgProtocol[] protocols = values();
            for (MsgProtocol protocol : protocols) {
                if (protocol.getCode().equals(code)) {
                    return protocol;
                }
            }
            throw new IllegalArgumentException("未知的报文通信协议：" + code);
        }

    }

    /**
     * 报文头策略
     */
    public enum HeadStrategy {

        HEAD_STRATEGY_00("00", "无"),

        HEAD_STRATEGY_01("01", "8位报文长度，不足左补0");

        private String code;

        private String name;

        HeadStrategy(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public String getName() {
            return name;
        }

        public static HeadStrategy getInstance(String code) {
            HeadStrategy[] strategies = values();
            for (HeadStrategy strategy : strategies) {
                if (strategy.getCode().equals(code)) {
                    return strategy;
                }
            }
            throw new IllegalArgumentException("未知的报文头策略：" + code);
        }

    }

}
